import request from '@/utils/request'
import { OssConfigForm, OssConfigQuery, OssConfigVo } from './types'
import { AxiosPromise, AxiosResponse } from 'axios'

enum Api {
  list = '/resource/oss/config/list',
  add = '/resource/oss/config/add',
  edit = '/resource/oss/config/edit',
  delete = '/resource/oss/config/delete',
  detail = '/resource/oss/config/getDetail',
  changeStatus = '/resource/oss/config/changeStatus',
}

// 查询对象存储配置列表
export function listOssConfig(query: OssConfigQuery): AxiosPromise<AxiosResponse<OssConfigVo[]>> {
  return request({
    url: Api.list,
    method: 'post',
    data: query,
  })
}

// 查询对象存储配置详细
export function getOssConfig(ossConfigId: string | number): AxiosPromise<OssConfigVo> {
  return request({
    url: Api.detail,
    method: 'post',
    data: ossConfigId,
  })
}

// 编辑、保存
export const saveOssConfig = (data: OssConfigForm) => {
  return request({
    url: !data.id ? Api.add : Api.edit,
    method: 'post',
    data,
  })
}

// 删除对象存储配置
export function delOssConfig(ossConfigId: string | undefined) {
  return request({
    url: Api.delete,
    method: 'post',
    data: ossConfigId,
  })
}

// 对象存储状态修改
export function changeOssConfigStatus(id: string, status: string) {
  const data = {
    id: id,
    status,
  }
  return request({
    url: Api.changeStatus,
    method: 'post',
    data,
  })
}
